//
//  HYMeetingRemarkCell.m
//  Booking
//
//  Created by Duntech on 2018/4/25.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMeetingRemarkCell.h"

@interface HYMeetingRemarkCell () <UITextViewDelegate>

@property (nonatomic,strong) UILabel *remarkNumLabel;
@property (nonatomic,strong) SAMTextView *remarkTextView;

@end

@implementation HYMeetingRemarkCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.remarkTextView];
        [self.contentView addSubview:self.remarkNumLabel];
    }
    return self;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    [_remarkTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.contentView);
    }];
    
    
    [_remarkNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-10);
    }];
    
    
}

#pragma mark - textViewDelegate
- (void)textViewDidChange:(UITextView *)textView{
    self.remarkNumLabel.text = [NSString stringWithFormat:@"%d/200",(int)textView.text.length];
    if (self.inputTextChangeBlock) {
        
        self.inputTextChangeBlock(textView.text);
    }
}

- (void)setRemarkStr:(NSString *)remarkStr{
    
    _remarkStr = remarkStr;
    _remarkTextView.text = remarkStr;
}

#pragma mark - lazyload

- (UILabel *)remarkNumLabel{
    
    if (!_remarkNumLabel) {
        _remarkNumLabel = [UILabel new];
        _remarkNumLabel.textColor = RGBColor(178, 178, 178);
        _remarkNumLabel.font = KFitFont(15);
        _remarkNumLabel.text = @"0/200";
    }
    return _remarkNumLabel;
}

- (SAMTextView *)remarkTextView{
    
    if (!_remarkTextView) {
        _remarkTextView = [[SAMTextView alloc] init];
        _remarkTextView.font = KFitFont(16);
        _remarkTextView.placeholder = NSLocalizedString(@"meetingRemark", nil);
        _remarkTextView.delegate = self;
    }
    return _remarkTextView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
